We have already seen one function. The main function is called when our C program starts. However our C program can contain many functions. Each function is made up of a function header and a block of code. A function header does a number of things:

  1. It gives the function a name (which is an identifier for that function)

  2. It tells the compiler the type of variable which the function returns (if any)

  3. It tells the compiler the type and identifiers of parameters which the function accepts (if any).

We have seen that the main function in our program doesn't return any values, nor does it accept any parameters. If we are simply writing a function to do a job this may be OK, however we often write functions which work on an input and produce an output.

The simple function above doesn't actually do anything, but it does show you how functions are obeyed. When the function is called the execution changes to the block of code which makes up the function body. When the program reaches the end of this block it returns to the line immediately following the function call.

The block of code which follows the header is sometimes called the function body.